#define  _CRT_SECURE_NO_WARNINGS
class KthLargest {
public:
    KthLargest(int k, vector<int>& nums) {
        _k = k;
        for (auto e : nums)
        {
            if (q.size() == k)
            {
                if (q.top() < e)q.pop(), q.push(e);
            }
            else q.push(e);
        }
    }

    int add(int val) {
        if (q.size() == _k)
        {
            if (q.top() < val)q.pop(), q.push(val);
        }
        else q.push(val);
        return q.top();
    }
    int _k;
    priority_queue<int, vector<int>, greater<int>> q;
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */